package com.yyaccp.easybuy.security.service;

import com.yyaccp.easybuy.security.vo.LoginUser;
import com.yyaccp.easybuy.security.vo.MockData;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 模拟从数据库查询用户以及对应的角色
        System.out.println("从数据库查询用户、角色和权限");
        LoginUser loginUser = MockData.get(username);
        if (loginUser == null) {
            throw new UsernameNotFoundException("UsernameNotFoundException：" + username);
        }
        return loginUser;
    }
}
